<template>
    <view class="task_detail_container" v-if="taskDetail&&attendTaskUserList">
        <!-- 分享 -->
        <view class="share_task_block" @tap="showShare()" :style="{background:defaultColor}">
            <image class="share_task_icon" src="https://image1.sansancloud.com/xianhua/2020_6/29/10/19/27_442.jpg?x-oss-process=style/preview_120"></image>
        </view>
        <posters-user-info-component :ewmImgUrl="ewmImgUrl" :posterTitle='posterTitle' v-if="posterState" @closePoaster="getChilrenPoster"></posters-user-info-component>
        <view class="zhezhao" v-if="showTypeTwo" @tap="closeTwoZhezhao"></view>
        <view class="select_share_list" :animation="animationDataTwo">
            <view class="select_share_item" v-for="(item, index) in shareTypeData" :key="index">
               <text class="select_share_name" @click.stop="showPoster" v-if="item.type=='text'">{{item.name}}</text>
               <button open-type="share" class="select_share_name" v-else>{{item.name}}</button>
            </view>
            <view class="select_share_item cancel_select_share" @tap="closeTwoZhezhao">
               <text class="select_share_name">取消</text>
            </view>
       </view>
        <view class="task_base_info_block">
            <view class="task_base_info_top">
                <text class="task_type" :style="{background:defaultColor}" v-if="taskDetail.taskMode==1">抢单</text>
                <text class="task_type" :style="{background:defaultColor}" v-if="taskDetail.taskMode==2">预选</text>
                <image :style="{background:defaultColor}" src="https://image1.sansancloud.com/xianhua/2020_5/8/11/15/27_69.jpg?x-oss-process=style/preview_120" class="price_icon"></image>
                <text :style="{color:defaultColor}" class="task_price" v-if="taskDetail.priceMode==0">免费</text>
                <text :style="{color:defaultColor}" class="task_price" v-if="taskDetail.priceMode==1">可议价</text>
                <view :style="{color:defaultColor}" class="task_price" v-if="taskDetail.priceMode==1">
                    ￥{{taskDetail.minPrice}}<text v-if="taskDetail.maxPrice==-1">起</text><text v-else>~{{taskDetail.maxPrice}}</text>
                </view>
                <text :style="{color:defaultColor}" class="task_price" v-if="taskDetail.priceMode==2">￥{{taskDetail.taskPrice}}</text>
                <text :style="{color:defaultColor}" class="over_time" v-if="taskDetail.taskStatus==0">未发布</text>
                <text :style="{color:defaultColor}" class="over_time" v-if="taskDetail.taskStatus==1">待审核</text>
                <text :style="{color:defaultColor}" class="over_time" v-if="taskDetail.taskStatus==2">审核拒绝</text>
                <view class="over_time" v-if="(taskDetail.taskStatus==3||taskDetail.taskStatus==4)&&taskDetail.dayDiff">剩<text :style="{color:defaultColor}"> {{taskDetail.dayDiff}} </text>天<text :style="{color:defaultColor}"> {{taskDetail.hours}} </text>小时</view>
                <view :style="{color:defaultColor}" class="over_time" v-if="(taskDetail.taskStatus==3||taskDetail.taskStatus==4)&&!taskDetail.dayDiff">任务时间已过期</view>
                <!-- <text :style="{color:defaultColor}" class="over_time" v-if="taskDetail.taskStatus==4">任务进行中</text> -->
                <text :style="{color:defaultColor}" class="over_time" v-if="taskDetail.taskStatus==5">任务已执行</text>
                <text :style="{color:defaultColor}" class="over_time" v-if="taskDetail.taskStatus==6">任务完成</text>
                
            </view>
            <text class="task_name">{{taskDetail.name}}</text>
            <view class="task_base_info_bottom">
                <view class="task_base_info_bottom_left">
                    <text class="task_classify">{{taskDetail.belongTaskTypeName}}</text>
                    <text class="task_order" :style="{color:defaultColor,border:'1rpx solid '+defaultColor}" v-if="taskDetail.topOrder>0">顶</text>
                </view>
                <view class="task_base_info_bottom_right">
                    <view class="user_level">
                        <!-- setting.platformSetting.secondColor -->
                        <view class="fx_user_parentPlatformUser" :style="{background:defaultColor}">
                          <image class="fx_recommend_icon" src="https://image1.sansancloud.com/zhihuishangwu/2019_11/15/22/51/10_91.jpg?x-oss-process=style/preview_120"></image>
                          <text :style="'color:' + '#fff'">{{taskDetail.belongPlatformUserLevelName||'普通用户'}}</text>
                        </view> 
                    </view>
                    <text class="user_name">发布者：{{taskDetail.belongPlatformUserName}}</text>
                </view>
            </view>
        </view>
        <view class="task_progress_block">
            <view class="task_progress_title">
                <view class="task_progress_title_left">
                    <image src="https://image1.sansancloud.com/xianhua/2020_5/8/14/19/21_51.jpg?x-oss-process=style/preview_120" class="task_progress_title_icon"></image>
                    <text class="task_progress_title_text">任务进度</text>
                    <view class="task_progress_title_curstate" :style="{color:defaultColor}">
                        <text v-if="taskDetail.taskStatus==1">发布需求</text>
                        <text v-if="taskDetail.taskStatus==3">服务报名</text>
                        <text v-if="taskDetail.taskStatus==4">任务进行中</text>
                        <text v-if="taskDetail.taskStatus==5">等待验收</text>
                        <text v-if="taskDetail.taskStatus==6">完成</text>
                    </view>
                </view>
                <view class="task_progress_title_right" :style="{background:taskDetail.payedPrice<=0?'#ccc':defaultColor}">
                    <image src="https://image1.sansancloud.com/xianhua/2020_5/8/14/29/44_241.jpg?x-oss-process=style/preview_120" class="tip_price_icon"></image>
                    <text class="tip_price" v-if="taskDetail.payedPrice<=0">无托管赏金</text>
                    <text class="tip_price" v-else>已托管￥{{taskDetail.payedPrice}}赏金</text>
                </view>
            </view>
            <view class="task_progress_bar">
                <view class="task_progress_list">
                    <view class="task_progress_line"></view>
                    <view class="task_progress_item" v-for="(item,index) in taskProgressList" :key='index'>
                        <view class="task_progress_item_top">
                            <view class="task_progress_item_round" :style="{background:item.state<=taskDetail.taskStatus?defaultColor:'#ccc'}">
                                <image class="task_progress_item_round_icon" v-if="item.state==taskDetail.taskStatus" src="https://image1.sansancloud.com/xianhua/2019_4/17/15/9/16_251.jpg?x-oss-process=style/preview_120"></image>
                            </view>
                        </view>
                        <text class="task_progress_item_name" :style="{color:item.state==taskDetail.taskStatus?defaultColor:'#444'}">{{item.name}}</text>
                    </view>
                </view>
            </view>
        </view>
        <view class="task_content_block">
            <view class="task_content_title">
                任务详情
            </view>
            <view class="task_content">
                <text>{{taskDetail.content}}</text>
            </view>
            <view class="task_content_img">
                <text class="task_content_img_title">附件：</text>
                <view class="task_content_img_list">
                    <image @tap="lookBigImage" :data-imageUrl="taskDetail.imagesArr" :data-index="index" :src="item" mode="aspectFill" class="task_content_img_item" v-for="(item,index) in taskDetail.imagesArr" :key="index"></image>
                </view>
            </view>
        </view>
        <view class="task_content_block" v-if="loginUser">
            <view class="task_content_title">
                更多信息
            </view>
            <view class="task_content">
                <check-form-detail-component :paddingState='false' ref="checkFormDetail" id="checkFormDetail" :showBtn="false" :formCommitId="taskDetail.moreInfoCustomFormCommitId" v-if="taskDetail"></check-form-detail-component>
            </view>
        </view>
        <!-- 参与人员列表 -->
        <view class="attend_task_user_list_block">
            <view class="attend_task_user_list_title">
                <text class="attend_task_user_list_title_left">稿件信息</text>
                <view class="attend_task_user_state_list">
                    <view class="attend_task_user_state_item"  @click='selectAttendTaskUserList(item.state)' :style="{borderBottom:'4rpx solid '+(curAttendTaskUserState==item.state?defaultColor:'#fff')}" v-for="(item,index) in attendTaskUserStateList" :key='index'>
                        <text class="attend_task_user_state_name" :style="{color:curAttendTaskUserState==item.state?defaultColor:''}">{{item.name}}</text>
                    </view>
                </view>
            </view>
            <view class="attend_task_user_list" v-if="attendTaskUserList&&attendTaskUserList.length!=0">
                <view class="attend_task_user_item" v-for="(item,index) in attendTaskUserList" :key="index">
                    <view class="attend_task_user_info" :style="{marginBottom:item.content?'20rpx':''}">
                        <image :src="item.belongServant.icon" class="attend_task_servant_icon" :data-url="'chat_room.html?puid='+item.belongPlatformUserId+'&puname='+item.belongPlatformUserName" @tap='tolinkUrl'></image>
                        <text class="attend_task_servant_name">{{item.belongServant.name}}</text>
                        <text class="attend_task_answer" :style="{color:'#fff',backgroundColor:defaultColor,border:'1rpx solid '+defaultColor}" v-if="item.belongServant.levelValue">{{item.belongServant.levelName}}</text>
                        <text class="attend_task_answer" v-if="taskDetail.priceMode==1&&taskDetail.taskStatus>=2&&loginUser&&(loginUser.platformUser.id==taskDetail.belongPlatformUserId||loginUser.platformUser.id==item.belongPlatformUserId)" :style="{color:defaultColor,border:'1rpx solid '+defaultColor}">议价结果:￥{{item.needConfirmChangeTaskPrice==1?item.prechangeTaskPrice:item.needPayPrice}}</text>
                        <image src="https://image1.sansancloud.com/xianhua/2020_5/13/16/17/24_952.jpg?x-oss-process=style/preview_120" v-if="item.status==1||item.status==2" class="attend_task_state"></image>
                        <view class="attend_task_state attend_task_text_state" v-if="item.status==4||item.status==5||item.status==6" :style="{color:defaultColor,border:'1rpx solid '+defaultColor}">
                            <text v-if="item.status==4">进行中</text>
                            <text v-if="item.status==5">已执行</text>
                            <text v-if="item.status==6">已完成</text>
                            <text v-if="item.status==8">已评价</text>
                        </view>
                    </view>
                    <view class="attend_task_user_content" v-if="item.content">
                        <text class="attend_task_user_content_rich">{{item.content}}</text>
                        <view class="attend_task_user_content_img_list">
                            <image mode="aspectFill" @tap="lookBigImage" :data-imageUrl="item.imageArr" :data-index="imgIndex" :src="imgItem" class="attend_task_user_content_img_item" v-for="(imgItem,imgIndex) in item.imageArr" :key="imgIndex"></image>
                        </view>
                    </view>
                    <view class="attend_task_user_bottom">
                        <view class="attend_task_user_time">
                            <image class="attend_task_user_time_icon" src="https://image1.sansancloud.com/xianhua/2020_3/27/11/6/34_494.jpg?x-oss-process=style/preview_120"></image>
                            {{item.attendedTime}}
                        </view>
                        <view class="attend_task_user_fun_list_block">
                            <view class="attend_task_user_fun_list" v-if="loginUser&&loginUser.platformUser.id==taskDetail.belongPlatformUserId">
                                <!-- <block v-for="(attendFunItem,attendFunIndex) in attendFunList" :key="attendFunIndex"> -->
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(1,item.id)" v-if="item.status==0">
                                        <text class="attend_task_user_fun_item_text">选中</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(3,item.id)" v-if="item.status==0">
                                        <text class="attend_task_user_fun_item_text">淘汰</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(4,item.id,taskDetail.id)" v-if="item.status==5&&!(item.payedStatus==0&&item.needPayedType==2)">
                                        <text class="attend_task_user_fun_item_text">完成</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(5,item.id,taskDetail.id)" v-if="item.status==2">
                                        <text class="attend_task_user_fun_item_text">开始任务</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(6,item.id,taskDetail.id)" v-if="item.status>1 && item.status<5">
                                        <text class="attend_task_user_fun_item_text">修改价格</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(7,item.id,taskDetail.id)" v-if="item.payedStatus==0&&item.needPayedType==2">
                                        <text class="attend_task_user_fun_item_text">支付尾款</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(8,item.id,taskDetail.id)" v-if="item.payedStatus==0&&item.needPayedType==1">
                                        <text class="attend_task_user_fun_item_text">预付订单</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click="sureChangeAttendTaskStateFun(9,item.id,taskDetail.id,item)" v-if="item.status==6&&!item.servantCommentId">
                                        <text class="attend_task_user_fun_item_text">评价</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" v-if="item.servantCommentId">
                                        <text class="attend_task_user_fun_item_text">已评价</text>
                                    </view>
                                    <view class="attend_task_user_fun_item" @click.stop="tolinkUrl('process_list.html?processInstanceId='+item.processInstanceId)" v-if="item.processInstanceId>0">
                                        <text class="attend_task_user_fun_item_text">查看流程</text>
                                    </view>
                                   <!-- <view class="attend_task_user_fun_item" v-if="item.status==4">
                                        <text class="attend_task_user_fun_item_text">
                                            任务进行中
                                        </text>
                                    </view> -->
                                <!-- </block> -->
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="noproduct" v-else>
              <image mode="widthFix" src='https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120'></image>
              <text>没有相关作品</text>
            </view>
        </view>
        <view class="task_bottom_btn_block" @click="attendTaskFun" v-if="loginUser&&loginUser.platformUser.managerServantId">
                <text class="task_bottom_btn" :style="{background:loginUser&&loginUser.platformUser.managerServantId&&taskDetail.servantAttendList.length==0&&(taskDetail.taskStatus==3||taskDetail.taskStatus==4)&&attendTaskUserNum<taskDetail.attendServantCount?defaultColor:'#ccc'}">
                    参与任务
                </text>
        </view>
       <view class="task_bottom_btn_block" @click="applyServantFun" v-else-if="loginUser&&loginUser.platformUser">
            <text class="task_bottom_btn" :style="{background:defaultColor}">
               申请成为{{properties.jiedanren||'服务员'}}
            </text>
        </view>
       <view class="task_bottom_btn_block" @click="toLoginFun" v-else-if="!loginUser">
            <text class="task_bottom_btn" :style="{background:defaultColor}">
               您还未登录！去登录~
            </text>
        </view>
        <!-- 填写表单弹窗动画 -->
        <view class='zhezhao' v-if="showAttendForm||showCommentState||applyServantState" @tap='closeZhezhao'></view>
        <view class='popupFormDetail' :animation="animationData" :style="{bottom:showAttendForm?'-200rpx':'-600rpx'}">
          <view class='form_title' >
            <text ></text>
            <text>请填写以下信息</text>
            <image class='close_popup_icon' src='https://image1.sansancloud.com/xianhua/2019_7/31/15/25/40_755.jpg?x-oss-process=style/preview_120' @click='closeZhezhao'></image>
          </view>
          <scroll-view scroll-y  style='max-height:700rpx'>
            <view v-if="sendOptionData&&sendOptionData.customFormId&&(showAttendForm||showCommentState||applyServantState)">
               <form-detail-component id="submitTaskForm" :receiveData="sendOptionData" :showTitle="true" :showBtn="false" @sendDataFun="getDataFun"></form-detail-component><!-- 弹窗-->
            </view>
            <view class="comments_other_block" v-if="showCommentState">
                <view class="comments_other_item" style="flex-direction: column">
                    <text class="comments_other_item_title" style="margin-bottom: 10rpx;">评论内容</text>
                    <textarea class="comments_textarea" maxlength="-1" auto-height="" @input="saveSearchValue" placeholder='请输入您的评论内容'></textarea>
                </view>
                <view class="comments_other_item" style="align-items: center">
                    <text class="comments_other_item_title">评分等级</text>
                    <view class="star_container">
                      <view class="star" data-scroll="1" @tap="productScroll">
                        <block v-if="otherCommentData.pingfen > 0"><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_803.jpg?x-oss-process=style/preview_120"></image></block>
                        <block v-else><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_828.jpg?x-oss-process=style/preview_120"></image></block>
                      </view>
                      <view class="star" data-scroll="2" @tap="productScroll">
                        <block v-if="otherCommentData.pingfen > 1"><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_803.jpg?x-oss-process=style/preview_120"></image></block>
                        <block v-else><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_828.jpg?x-oss-process=style/preview_120"></image></block>
                      </view>
                      <view class="star" data-scroll="3" @tap="productScroll">
                        <block v-if="otherCommentData.pingfen > 2"><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_803.jpg?x-oss-process=style/preview_120"></image></block>
                        <block v-else><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_828.jpg?x-oss-process=style/preview_120"></image></block>
                      </view>
                      <view class="star" data-scroll="4" @tap="productScroll">
                        <block v-if="otherCommentData.pingfen > 3"><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_803.jpg?x-oss-process=style/preview_120"></image></block>
                        <block v-else><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_828.jpg?x-oss-process=style/preview_120"></image></block>
                      </view>
                      <view class="star" data-scroll="5" @tap="productScroll">
                        <block v-if="otherCommentData.pingfen > 4"><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_803.jpg?x-oss-process=style/preview_120"></image></block>
                        <block v-else><image src="https://image1.sansancloud.com/naifen/2019_5/31/17/7/11_828.jpg?x-oss-process=style/preview_120"></image></block>
                      </view>
                    </view>
                </view>
            </view>
            </scroll-view>
        </view>
        <view v-if="sendOptionData&&(showAttendForm||showCommentState||applyServantState)" class='submitBtn' :style='{background:defaultColor}' @click='submitData'>
          <text v-if="showCommentState">提交评论</text>
          <text v-if="applyServantState">提交审核</text>
          <text v-if="showAttendForm">提交资料</text>
        </view>
        <block v-if="isShowConfirm">
          <view class='toast-box'>
            <view class='toastbg'></view>
            <view class='showToast'>
                <view class='toast-title' :style="{background:defaultColor}">
                    <text>议价结果</text>
                </view>
                <view class='toast-main'>
                    <view class='toast-input'>
                        <input type='text' placeholder='输入议价价格' @input='setValue' data-name='stuEidtName'></input>
                    </view>
                </view>
                <view class='toast-button'>
                    <view class='button1'>
                        <button @tap='cancel'>取消</button>
                    </view>
                    <view class='button2'>
                        <button data-url="../allOrder/allOrder" @tap='confirmAcceptance'>确定</button>
                    </view>
                </view>
            </view>
        </view>
      </block>
      <!-- 发布留言 -->
      <!-- <view class="zhezhao" v-if="showCommentState" @tap="closeCommentBan"></view>
      <view class="comments_part" v-if="showCommentState">
        <input class="comments_input b" focus @confirm="sendComments" @input="saveData" :value="commentValue" cursor-spacing="130" placeholder="发表评论..." maxlength="100"></input>
        <image class="comments_img_icon" @tap="sendComments" src="https://image1.sansancloud.com/jianzhan/2019_3/13/18/4/57_119.jpg?x-oss-process=style/preview_120" mode="aspectFitf"></image>
      </view> -->
    </view>
</template>

<script>
import { socketFun } from "../../wxcomponents/public/json2Form";
export default {
  data() {
    return {
      taskDetail:null,
      taskId:0,
      setting:null,
      properties:{},
      loginUser:null,
      secondColor:'',
      defaultColor:'',
      showAttendForm:false,
      animationData:null,
      sendOptionData:null,
      isShowConfirm:false,
      taskProgressList:[
          {name:'发布需求',state:1},
          {name:'服务报名',state:3},
          {name:'任务进行中',state:4},
          {name:'等待验收',state:5},
          {name:'完成',state:6},
      ],
      curAttendTaskUserState:-1,
      attendTaskUserStateList:[
          {name:'全部',state:-1},
          {name:'中标',state:1},
          {name:'备选',state:2},
          {name:'淘汰',state:3},
          {name:'我的',state:4},
      ],
      attendTaskUserList:null,
      attendTaskUserNum:10000,
      taskAttendId:0,
      taskPrice:0,
      curState:0,
      // attendFunList:[
      //     {name:'选中',state:1},
      //     {name:'淘汰',state:3},
      //     {name:'完成',state:4},
      // ],
      listPage:{
          page: 1,
          pageSize: 20,
          totalSize: 0,
          taskId: "",
      },
      showCommentState:false,
      otherCommentData:{commentStr:'',pingfen:5},
      curAttendUserData:null,
      popupType:'',
      applyServantState:false,
      showTypeTwo: false,
      animationDataTwo: null,
      posterState:false,
      shareTypeData: [
        {name: '发送给朋友',type: 'botton'},
        {name: '生成海报',type: 'text'},
      ],
      ewmImgUrl:'',
      posterTitle:'',
    };
  },
  props: {},

  /*onload*/
  onLoad: function (options) {
    let that=this;
    if(options.taskId){
        setTimeout(function(){
            that.setData({taskId:options.taskId})
            that.getData(options.taskId);
            that.listPage.taskId=options.taskId
        },500)
    }
    let loginUser=getApp().globalData.loginUser||null;
    if (loginUser) {
      that.checkState();
    } else {
      getApp().globalData.addLoginListener(that);
    }
    console.warn("======onLoad:options======", options, getApp().globalData.setting);
  },
  onReady: function () {
    
  },
  onShow: function () {
    let that=this;
	that.setData({
        setting:getApp().globalData.setting,
        properties: getApp().globalData.properties,
        defaultColor:getApp().globalData.setting.platformSetting.defaultColor,
        secondColor:getApp().globalData.setting.platformSetting.secondColor,
       })
    wx.setNavigationBarColor({
      frontColor: getApp().globalData.setting.platformSetting?getApp().globalData.setting.platformSetting.topColor.toLowerCase():'',
      backgroundColor: getApp().globalData.setting.platformSetting?getApp().globalData.setting.platformSetting.topBgColor:''
    });
  },
  /* 分享 app.js862行*/
  onShareTimeline:function(){
    return this.shareFun();
  },
  onShareAppMessage: function (res) {
    // console.log(getApp().globalData.miniIndexPage);
    // return getApp().globalData.shareForFx2(getApp().globalData.miniIndexPage);
    console.log(res);
    return this.shareFun();
  },
  onPullDownRefresh: function () {
    let that = this; // 下拉刷新的时候首先判断存不存在tab
    console.log("下拉");
    if (getApp().globalData.loginUser) {
      that.checkState();
    } else {
      getApp().globalData.addLoginListener(that);
    }
    that.getData(that.taskId);
    wx.stopPullDownRefresh();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('===onReachBottom====');
    let that = this
    if (that.listPage.totalSize > that.listPage.page * that.listPage.pageSize) {
      that.listPage.page++
      that.findAttendTaskUserListFun(that.listPage,'upload');
    }else{
        wx.showToast({
          title: "到底了~",
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
    }
  },
  methods: {
    shareFun:function(){
        let that = this;
        that.closeZhezhao();
        let params = {
          taskId: that.taskId
        };
        let shareName = that.taskDetail.name;
        let shareAppMessageData = getApp().globalData.shareForFx2('task_detail', shareName, params, '', 'taskId');
        console.log('params:', params,shareAppMessageData,shareName);
        return shareAppMessageData;
    },
    toLoginFun:function(){
        let that=this;
        let url='login.html?url=';
        let backUrl='task_detail.html?taskId='+that.taskId;
        url+= encodeURIComponent(backUrl)
        getApp().globalData.linkEvent(url)
    },
    showShare: function () {
      this.setData({
        showTypeTwo: !this.showTypeTwo
      });
      let showTypeTwo = this.showTypeTwo;
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease-in-out'
      });
      console.log("=======popupFormPage==========", animation, this.showType);

      if (showTypeTwo) {
        animation.height(150).step();
      } else {
        animation.height(0).step();
      }

      this.setData({
        animationDataTwo: animation.export()
      });
    },
    // 关闭海报
    getChilrenPoster:function(e) {
      let that = this;
      that.setData({
        posterState: false
      });
    },
    closeTwoZhezhao: function () {
      this.setData({
        showTypeTwo: false
      });
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease-out'
      });
      animation.height(0).step();
      let setData = animation.export();
      this.setData({
        animationDataTwo: setData
      });
    },
    showPoster: function () {
      let that = this;
      let ewmImgUrl = getApp().globalData.getQrCode({
        type: "common_page",
        id: that.taskId,
        otherParams:{linkUrl:'task_detail',taskId: that.taskId}
      });
      let shareName = that.taskDetail.name;
      that.setData({
        ewmImgUrl: ewmImgUrl,
        posterTitle: shareName,
        posterState: true,
      });
    },
    // 申请服务人员
    applyServantFun:function(){
        let that=this;
        if(!that.properties.applyServantFormId){
            wx.showToast({
              title: '不可申请',
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
            return;
        }else{
            that.animationDataFun('applyServant')
        }
    },
    /* 商品评分 */
    productScroll: function (e) {
      let that = this;
      let otherCommentData = that.otherCommentData;
      let scoll = e.currentTarget.dataset.scroll;
      otherCommentData.pingfen = scoll;
      that.setData({
        otherCommentData: otherCommentData
      });
      console.log("==productScroll===",otherCommentData,that.otherCommentData)
    },
    saveSearchValue:function(e){
      let that = this;
      let otherCommentData = that.otherCommentData;
      let commentStr = e.detail.value;
      otherCommentData.commentStr = commentStr;
      this.setData({
        otherCommentData: otherCommentData
      })
      console.log("==saveSearchValue===",otherCommentData,that.otherCommentData)
    },
    setValue: function (e) {
      this.setData({
        taskPrice: e.detail.value
      })
    },
    cancel: function () {
      var that = this
      that.setData({
        isShowConfirm: false,
      })
    },
    confirmAcceptance:function(){
      var that = this
      that.setData({
        isShowConfirm: false,
      })
      if(that.curState==6){
          that.changeUserTaskPriceFun(that.taskAttendId)
      }else if(that.curState==1){
         that.changeAttendTaskStateFun(1,that.taskAttendId)   
      }
    },
    sureChangeAttendTaskStateFun:function(state,id,taskId,itemData){
        let that=this;
        let title='您确定要选中该作品吗？'
        if(state==3){
            title="您确定要淘汰该作品吗？"
        }else if(state==4){
            title="您确定要完成该作品吗？"
        }else if(state==5){
            title="您确定要开始该作者的任务吗？"
        }else if(state==6){
            title="您确定要修改议价价格吗？"
        }else if(state==7){
           title='您确定要支付尾款吗？' 
        }else if(state==8){
           title='您确定要预付订单吗？' 
        }else if(state==9){
            that.setData({taskAttendId: id,curState:state,curAttendUserData:itemData})
            that.showCommentFun();
           return
        }
        wx.showModal({
          title: '提示',
          content: title,
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
              that.setData({taskAttendId: id,curState:state})
              if(state==4){
                  that.finishAttendTaskFun(id,taskId)
              }else if(state==5){
                  that.startUserTaskFun(id,taskId)
              }else if(state==6){
                  that.setData({isShowConfirm: true})
              } else if(state==7||state==8){
                  that.createTaskOrderFun(state,id,taskId)
              }else{
                  if(state==1){
                      if(that.taskDetail.priceMode==1){
                          that.setData({isShowConfirm: true})
                      }
                  }else{
                    that.changeAttendTaskStateFun(state,id)
                  }
              }
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
    },
    showCommentFun:function(){
        console.log("===showCommentFun===",)
        let that=this;
        that.animationDataFun('commentServant')
    },
    //添加评论
    commentInput: function (formId) {
      console.log("===sendComments==", formId);
      var that = this;
      let data = {
        commentType:11,
        commitId:formId||0,
        itemId: that.taskAttendId,
        customFormId:that.taskDetail.taskType.commentCustomFormId||0,
        commentTargetType:26,
        targetId:that.curAttendUserData.belongServantId,
      };
      data=Object.assign({},data,that.otherCommentData)
      console.log('文本输入框: input_value :', data);
      let customIndex = getApp().globalData.AddClientUrl("/wx_comment_target.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          that.closeZhezhao();
          that.setData({otherCommentData:{commentStr:'',pingfen:5}})
          // that.otherCommentData={commentStr:'',pingfen:5},
          console.log('==res===', res);
          if (res.data.errcode == 0) {
            for(let i=0;i<that.attendTaskUserList.length;i++){
                if(that.attendTaskUserList[i].id==that.taskAttendId){
                     that.$set(that.attendTaskUserList[i],'servantCommentId',res.data.relateObj.id)
                }
            }
            console.log("==that.taskDetail==",that.attendTaskUserList)
            wx.showToast({
              title: "评论成功",
              icon: 'success',
              duration: 2000
            });
          } else {
            wx.showToast({
              title: "评论失败",
              icon: "none",
              duration: 2000
            });
          }
        }
      });
    },
    closeCommentBan:function(){
        console.log("===closeCommentBan===",)
        let that=this;
        that.setData({
          showCommentState: false
        });
    },
    createTaskOrderFun: function (state,itemId,taskId) {
      var that = this;
      let wxChatPayParam = {
        payType: 3,
        taskId:taskId,
        taskAttendId:itemId
      };
      let reqUrl="/wx_create_task_attend_prepay_order.html";
      if(state=='7'){
        reqUrl="/wx_create_task_attend_endpay_order.html";
      }
      let customIndex = getApp().globalData.AddClientUrl(reqUrl, wxChatPayParam, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data); //这里拿到订单数据
          //下面应该吊起支付
          console.log(res.data);
          let orderNo = res.data.relateObj.orderNo;
          if(res.data.errcode==0){
            // that.payByWechat(orderNo);
            let url='edit_order.html?orderNo='+orderNo;
            that.tolinkUrl(url)
          }
        },
        fail: function () {},
        complete: function () {
        }
      });
    },
    changeUserTaskPriceFun:function(id){
        let that = this
        let params={
            taskId:that.taskDetail.id,
            taskAttendId:id,
            taskPrice:that.taskPrice,
        }
        console.log("===params==",params)
        var customIndex = getApp().globalData.AddClientUrl("/wx_change_task_attended_price.html", params)
        getApp().globalData.showToastLoading('loading', true)
        wx.request({
          url: customIndex.url,
          header: getApp().globalData.header,
          success: function (res) {
            wx.hideLoading()
            console.log(res.data)
            let data=res.data.relateObj;
            if(res.data.errcode==0){
                wx.showToast({
                  title: "操作成功",
                  icon:'success',
                  duration: 1000
                });
                setTimeout(function(){
                  that.findAttendTaskUserListFun(that.listPage)
                },1000)
            }else{
                wx.showToast({
                  title: res.data.errMsg,
                  image: '/wxcomponents/images/icons/tip.png',
                  duration: 1000
                });
            }
            wx.hideLoading()
          },
          fail: function (res) {
            console.log("fail")
            wx.hideLoading()
            getApp().globalData.loadFail()
          }
        })
    },
    startUserTaskFun:function(id,taskId){
        let that = this
        let params={
            taskId:taskId,
            taskAttendId:id,
        }
        console.log("===params==",params)
        var customIndex = getApp().globalData.AddClientUrl("/wx_start_task_attend.html", params)
        getApp().globalData.showToastLoading('loading', true)
        wx.request({
          url: customIndex.url,
          header: getApp().globalData.header,
          success: function (res) {
            wx.hideLoading()
            console.log(res.data)
            let data=res.data.relateObj;
            if(res.data.errcode==0){
                wx.showToast({
                  title: "操作成功",
                  icon:'success',
                  duration: 1000
                });
                setTimeout(function(){
                  that.findAttendTaskUserListFun(that.listPage)
                },1000)
            }else{
                wx.showToast({
                  title: res.data.errMsg,
                  image: '/wxcomponents/images/icons/tip.png',
                  duration: 1000
                });
            }
            wx.hideLoading()
          },
          fail: function (res) {
            console.log("fail")
            wx.hideLoading()
            getApp().globalData.loadFail()
          }
        })
    },
    finishAttendTaskFun:function(id,taskId){
      let that = this
      let params={
          taskId:taskId,
          taskAttendId:id,
      }
      console.log("===params==",params)
      var customIndex = getApp().globalData.AddClientUrl("/wx_task_attend_finished_confirm.html", params)
      getApp().globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          let data=res.data.relateObj;
          if(res.data.errcode==0){
              wx.showToast({
                title: "操作成功",
                icon:'success',
                duration: 1000
              });
              that.$set(that.taskDetail,'taskStatus',6)
              setTimeout(function(){
                that.findAttendTaskUserListFun(that.listPage)
              },1000)
          }else{
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 1000
              });
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          getApp().globalData.loadFail()
        }
      })
    },
    changeAttendTaskStateFun:function(state,id){
      let that = this
      let params={
          taskId:that.taskDetail.id,
          state:state,
          taskAttendId:id,
          taskPrice:that.taskPrice,
      }
      console.log("===params==",params)
      var customIndex = getApp().globalData.AddClientUrl("/wx_selected_task_attended.html", params)
      getApp().globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          let data=res.data.relateObj;
          if(res.data.errcode==0){
              wx.showToast({
                title: "操作成功",
                icon:'success',
                duration: 1000
              });
              setTimeout(function(){
                that.findAttendTaskUserListFun(that.listPage)
              },1000)
          }else{
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 1000
              });
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          getApp().globalData.loadFail()
        }
      })
    },
    checkState: function () {
      let that = this;
      console.log('======checkState.loginUser======', getApp().globalData.loginUser,getApp().globalData.setting);
      that.setData({
        loginUser: getApp().globalData.loginUser
      });
    },
    selectAttendTaskUserList:function(state){
        let that=this;
        that.setData({curAttendTaskUserState:state})
        that.findAttendTaskUserListFun(that.listPage,state)
    },
    findAttendTaskUserListFun:function(param,state){
        let that = this
        let params={
            state:state||-1,
        }
        console.log("===params==",params,param)
        params=Object.assign({},params,param)
        var customIndex = getApp().globalData.AddClientUrl("/wx_find_task_attendeds.html", params)
        getApp().globalData.showToastLoading('loading', true)
        wx.request({
          url: customIndex.url,
          header: getApp().globalData.header,
          success: function (res) {
            wx.hideLoading()
            console.log(res.data)
            let data=res.data.relateObj.result;
            if(data&&data.length!=0){
                for(let i=0;i<data.length;i++){
                    if(data[i].images){
                        data[i].imageArr=JSON.parse(data[i].images)
                    }
                }
            }
            that.listPage.pageSize = res.data.relateObj.pageSize
            that.listPage.page = res.data.relateObj.curPage
            that.listPage.totalSize = res.data.relateObj.totalSize
            let dataArr = that.attendTaskUserList;
            console.log("===data====",data)
            if (param.page == 1) {
              dataArr = []
            }
            if (!data || data.length == 0) {
              that.setData({ attendTaskUserList: [] })
            } else {
              if (dataArr == null) { dataArr = [] }
              dataArr = dataArr.concat(data)
              that.setData({ attendTaskUserList: dataArr })
            }
            if(params.state==-1){
                if(res.data.relateObj.totalSize==that.taskDetail.attendServantCount&&that.taskDetail.taskStatus!=4){
                    console.log("===taskStatus===",)
                    that.$set(that.taskDetail,'taskStatus',4)
                }
                that.setData({attendTaskUserNum:res.data.relateObj.totalSize||0})
                console.log("attendTaskUserNum",dataArr.length,that.attendTaskUserNum)
            }
            wx.hideLoading()
          },
          fail: function (res) {
            console.log("fail")
            wx.hideLoading()
            getApp().globalData.loadFail()
          }
        })
    },
    attendTaskFun:function(){
        let that=this;
        if(that.taskDetail.taskStatus<3){
            wx.showToast({
              title: "暂不能参与！",
                image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            });
            return
        }
        if(that.taskDetail.servantAttendList&&that.taskDetail.servantAttendList.length>0){
            wx.showToast({
              title: "您已参与过了！",
                image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            });
            return
        };
        if(that.attendTaskUserList.length>=that.taskDetail.attendServantCount){
            wx.showToast({
              title: "参与人数已满！",
                image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            });
            return
        };
        if(that.loginUser&&!that.loginUser.platformUser.managerServantId){
            wx.showToast({
              title: "您还不是服务商！",
                image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            });
            return
        };
        that.animationDataFun('attendTask')
    },
    animationDataFun:function(type){
        let that=this;
        let state=false;
        that.setData({popupType:type})
        if(type&&type=='attendTask'){
            let showAttendForm=!that.showAttendForm;
            that.setData({
              sendOptionData: { customFormId: that.taskDetail.attendCustomFormId },
              showAttendForm: showAttendForm,
            })
            console.log("showAttendForm",showAttendForm,that.sendOptionData)
        }else if(type&&type=='commentServant'){
            let showCommentState=!that.showCommentState;
            that.setData({
              sendOptionData: !that.taskDetail.taskType.commentCustomFormId?null:{ customFormId: that.taskDetail.taskType.commentCustomFormId||0},
              showCommentState: showCommentState,
            })
            console.log("showCommentState",showCommentState,that.sendOptionData)
        }else if(type&&type=='applyServant'){
            let applyServantState=!that.applyServantState;
            that.setData({
              sendOptionData: { customFormId:that.properties.applyServantFormId},
              applyServantState: applyServantState,
            })
            console.log("applyServantState",applyServantState,that.sendOptionData)
        }
        let animation = wx.createAnimation({
          duration: 400,
          timingFunction: 'ease',
        })
        animation.bottom('100rpx').step()
        that.setData({
          animationData: animation.export(),
        })
    },
    submitData:function(){
        let that=this;
        if(!that.sendOptionData.customFormId&&that.popupType=='commentServant'){
            that.commentInput()
        }else if(that.sendOptionData.customFormId&&that.popupType=='commentServant'){
            that.selectComponent("#submitTaskForm").formSubmit();
        }else{
            that.selectComponent("#submitTaskForm").formSubmit();
        }
    },
    getDataFun: function (e) {
      let that = this;
      console.log("===getDataFun===", e, e.detail.formId)
      if(that.popupType=='commentServant'){
          that.commentInput(e.detail.formId)
      }else if(that.popupType=='attendTask'){
          that.submitAttendTaskFun(e.detail.formId)
      }else if(that.popupType=='applyServant'){
          thatcloseZhezhao()
      }
    },
    closeZhezhao:function(){
      console.log("======closeZhezhao=========")
      let that=this;
      let bottomNum='-200rpx'
      let stateText=that.showCommentState?'showCommentState':'showAttendForm';
      if(stateText=='showCommentState'){
          bottomNum='-600rpx'
      }
      console.log("==bottomNum==",bottomNum)
      this.setData({ showAttendForm: false,showCommentState:false ,applyServantState:false})
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease',
      })
      animation.bottom(bottomNum).step()
      let setData = animation.export()
      this.setData({
        animationData: setData,
      })
    },
    submitAttendTaskFun:function(formCommitId){
      var that = this
      let params={
          taskId:that.taskDetail.id,
          customFormId:that.taskDetail.attendCustomFormId,
          formCommitId:formCommitId,
      }
      console.log("===params==",params)
      var customIndex = getApp().globalData.AddClientUrl("/wx_attend_task.html", params)
      getApp().globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          that.closeZhezhao()
          let data=res.data.relateObj;
          if(res.data.errcode==0){
              wx.showToast({
                title: "参与成功",
                icon:'success',
                duration: 1000
              });
              that.taskDetail.servantAttendList.splice(0,1,data)
              setTimeout(function(){
                that.listPage
                that.findAttendTaskUserListFun(that.listPage)
              },1000)
          }else{
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 1000
              });
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          getApp().globalData.loadFail()
        }
      })
    },
    /* 获取数据 */
    getData: function (taskId) {
      var that = this
      let params={
          taskId:taskId
      }
      console.log("===params==",params)
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_task_detail.html", params)
      getApp().globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          let data=res.data.relateObj;
          that.findAttendTaskUserListFun(that.listPage)
          if(data.images){
              data.imagesArr=JSON.parse(data.images);
          }
          if(data.taskEndTime){
            var endTim = data.taskEndTime;
            var dateEnd = new Date(endTim); //入场时间
            var dateBegin = new Date(); //现在的时间
            var dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
            if(dateDiff<=0){
                that.setData({ taskDetail: data })
                wx.hideLoading()
                return
            }
            var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
            var leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
            var hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数
            data.dayDiff=dayDiff;
            data.hours=hours
          }
          console.log("====data====",data)
          that.setData({ taskDetail: data })
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          getApp().globalData.loadFail()
        }
      })
    },
    lookBigImage: function (e) {
      console.log("111111111", e.currentTarget.dataset);
      let imgSrc = e.currentTarget.dataset.imageurl;
      let imgArray = [];
      let index = e.currentTarget.dataset.index;
      let PostImageSrc = [];
      console.log(imgSrc);

      for (let i = 0; i < imgSrc.length; i++) {
        imgArray.push(imgSrc[i]);
        PostImageSrc.push(imgSrc[i].replace(/http/, "https"));
      } 
      console.log(PostImageSrc);
      if (!imgSrc) {
        return;
      }
      wx.previewImage({
        current: imgArray[index],
        // 当前显示图片的http链接
        urls: imgArray // 需要预览的图片http链接列表

      });
    },
    /* 组件事件集合 */
    tolinkUrl: function (e) {
      console.warn("=======e=======", e);
      let linkUrl = e.currentTarget?e.currentTarget.dataset.url:e;
      getApp().globalData.linkEvent(linkUrl);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>